package ymr.game;

import ymr.gui.Button;

public class Player {
	private String name = ""; // name of the player
	private int points = 0; // player shall have some points..one day
	private Tile location; // current location of the player
	private boolean hasWon = false;
	private Game game;
	private Button button;
	private int orderInGame; //shows when player stepped into the game
	
	/**
	 * Player constructor
	 * @param name of the player
	 */
		public Player(String name, Game g){
		this.name = name;
		game = g;
	}
	
	/**
	 * Moves player forward
	 * @param steps shows how many times player moves
	 * @return current location
	 */
	public Tile movePlayer(int steps){
		location.removePlayer(this);
		for(int i=1; i<=steps; i++){
			if(!location.isEnd()){ //
				location = location.getNext();
				points++;
				if(location.isEnd()){
					System.out.println(name + " joudis loppu");
					game.setWinner(this);
					game.setGameOnFalse();
					break;
				}
			}
		}
		location.addPlayer(this);
		return location;
	}
	
	/**
	 * Get player's current location(tile)
	 * @return tile where player is
	 */
	public Tile getLocation(){
		return location;
	}
	/**
	 * @param t
	 */
	public void setLocation(Tile t){
		location = t;
	}
	
	/**
	 * @return name of the player
	 */
	public String getName(){
		return name;
	}
	
	/**
	 * @return player's points
	 */
	public int getPoints(){
		return points;
	}
	public void resetPoints(){
		points = 0;
	}
	
	public String toString(){
		return name;
	}

	public boolean isHasWon() {
		return hasWon;
	}

	public void setHasWon(boolean hasWon) {
		this.hasWon = hasWon;
	}

	public Button getButton() {
		return button;
	}

	public void setButton(Button button) {
		this.button = button;
	}

	public int getOrderInGame() {
		return orderInGame;
	}

	public void setOrderInGame(int orderInGame) {
		this.orderInGame = orderInGame;
	}
}